<template>
  <div class="app-container">
    <!-- 添加或修改服务记录对话框 -->
    <el-dialog title="完成订单" :visible.sync="open" width="50%" >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="订单编号" prop="num">
              <el-input v-model="form.num" :readonly="true" :disabled="true"  />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="服务人员" prop="receiveName">
              <el-input v-model="form.receiveName" placeholder="请选择服务人员" :readonly="true"  >
                <el-button slot="append" icon="el-icon-search" @click="openSelectReceive"></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="开始时间" prop="beginTime">
              <el-date-picker clearable size="small"
                v-model="form.beginTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择服务开始时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结束时间" prop="endTime">
              <el-date-picker clearable size="small"
                v-model="form.endTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择服务结束时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="图片">
              <imageUpload v-model="form.imgUrl"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            
          </el-col>
        </el-row>
        
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" :rows="2" v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
      <select-receive ref="selectReceiveForm"  v-if="receiveOpen" @finishSelected="finishSelectReceive"></select-receive>
    </el-dialog>
  </div>
</template>

<script>
import { finishService } from "@/api/business/order";
import ImageUpload from '@/components/ImageUpload';
import SelectReceive from './selectReceive';

export default {
  name: "Service",
  components: {
    ImageUpload,
    SelectReceive
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 服务记录表格数据
      serviceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      receiveOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        receiveId: null,
        receiveName: null,
        beginTime: null,
        endTime: null,
        imgUrl: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
  },
  methods: {
    init(data){
      this.reset();
      this.open = true;
      this.form.orderId = data.id;
      this.form.num = data.num;
    },
   
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderId: null,
        receiveId: null,
        receiveName: null,
        beginTime: null,
        endTime: null,
        imgUrl: null,
        createTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {         
            finishService(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.$emit("finishSelected");      
            });
        }
      });
    },
    openSelectReceive(){
      this.receiveOpen = true;
      this.$nextTick(()=>{
        this.$refs['selectReceiveForm'].init();
      });
    },
    finishSelectReceive(data){
      this.form.receiveId = data.userId;
      this.form.receiveName = data.nickName;      
    },
  }
};
</script>
